Skip to content

Conversation

@dkkplk
Copy link
Collaborator

@dkkplk dkkplk commented Jan 23, 2026

No description provided.

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Updates getReportUrl() to return a URL with properly encoded query parameters (notably [/]), and adds coverage to validate that behavior.

Changes:

  • Reworked PerfectoReportiumClient#getReportUrl() to rebuild the URL using URI + URIBuilder and (re)encode query parameters.
  • Added a unit test asserting correct encoding of query parameters in the report URL.
  • Updated an existing test assertion around relative report URLs.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 4 comments.

File Description
reportium-java/src/main/java/com/perfecto/reportium/client/PerfectoReportiumClient.java Rebuilds report URL via URIBuilder to apply URL encoding to query parameters.
reportium-java/src/test/java/com/perfecto/reportium/client/PerfectoReportiumClientTest.java Adds test for encoded query params and adjusts an existing expected report URL.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +229 to +247
URIBuilder uriBuilder = new URIBuilder()
.setScheme(originalUri.getScheme())
.setHost(originalUri.getHost())
.setPort(originalUri.getPort())
.setPath(originalUri.getPath());

// Parse and add query parameters - URIBuilder will encode them
if (originalUri.getQuery() != null) {
String[] pairs = originalUri.getQuery().split("&");
for (String pair : pairs) {
String[] keyValue = pair.split("=", 2);
if (keyValue.length == 2) {
uriBuilder.addParameter(keyValue[0], keyValue[1]);
} else {
uriBuilder.addParameter(keyValue[0], "");
}
}
}

Copy link

Copilot AI Jan 23, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

getQuery() returns the decoded query string, so splitting on '&' can break when a parameter value contains an encoded ampersand (%26) (it will be decoded to '&' before you split). Prefer parsing the raw query (getRawQuery) or, better, construct URIBuilder directly from the original URI/string so it handles query parsing/encoding correctly.

Suggested change
URIBuilder uriBuilder = new URIBuilder()
.setScheme(originalUri.getScheme())
.setHost(originalUri.getHost())
.setPort(originalUri.getPort())
.setPath(originalUri.getPath());
// Parse and add query parameters - URIBuilder will encode them
if (originalUri.getQuery() != null) {
String[] pairs = originalUri.getQuery().split("&");
for (String pair : pairs) {
String[] keyValue = pair.split("=", 2);
if (keyValue.length == 2) {
uriBuilder.addParameter(keyValue[0], keyValue[1]);
} else {
uriBuilder.addParameter(keyValue[0], "");
}
}
}
// Let URIBuilder parse the full original URI, including query parameters,
// to avoid manual splitting of the decoded query string.
URIBuilder uriBuilder = new URIBuilder(originalUri);

Copilot uses AI. Check for mistakes.
Comment on lines +229 to +247
URIBuilder uriBuilder = new URIBuilder()
.setScheme(originalUri.getScheme())
.setHost(originalUri.getHost())
.setPort(originalUri.getPort())
.setPath(originalUri.getPath());

// Parse and add query parameters - URIBuilder will encode them
if (originalUri.getQuery() != null) {
String[] pairs = originalUri.getQuery().split("&");
for (String pair : pairs) {
String[] keyValue = pair.split("=", 2);
if (keyValue.length == 2) {
uriBuilder.addParameter(keyValue[0], keyValue[1]);
} else {
uriBuilder.addParameter(keyValue[0], "");
}
}
}

Copy link

Copilot AI Jan 23, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This rebuilds the URI from scheme/host/port/path only, which drops other components like fragment (#...), user-info, and any original path encoding (getPath() is decoded). If the report URL can contain these, the returned URL will be altered. Using URIBuilder(originalUri) (or URIBuilder(reportUrl)) and only adjusting encoding as needed will preserve all components.

Suggested change
URIBuilder uriBuilder = new URIBuilder()
.setScheme(originalUri.getScheme())
.setHost(originalUri.getHost())
.setPort(originalUri.getPort())
.setPath(originalUri.getPath());
// Parse and add query parameters - URIBuilder will encode them
if (originalUri.getQuery() != null) {
String[] pairs = originalUri.getQuery().split("&");
for (String pair : pairs) {
String[] keyValue = pair.split("=", 2);
if (keyValue.length == 2) {
uriBuilder.addParameter(keyValue[0], keyValue[1]);
} else {
uriBuilder.addParameter(keyValue[0], "");
}
}
}
URIBuilder uriBuilder = new URIBuilder(originalUri);

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants